//! Package for the Object
package image;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;

import javax.imageio.ImageIO;

import process.*;

/*! Az objektumk osztalya */
public class PhysiObject {
	
	private double posX;
	private double posY;
	private long timestamp;
	private double vX;
	private double vY;
	private double aX;
	private double aY;
	private long count;
	//! Konstruktor
	/*!
	  \param message string
	*/
	public PhysiObject(){
		posX = 0;
		posY = 0;
		vX = 0;
		vY = 0;
		aX = 0;
		aY = 0;
		count = 0;
	}
	//! adattagokat aktualizalo fuggveny: meghatarozza a targy aktualis poziciojat, sebesseget es gyorsulasat
	/*!
	  \param int img OwnImae class
	  \param int long aktualis ido	  
	*/

	
/*
	public void actualize(OwnImage img, long timestamp){
		try{
			int[] pos=ProcIm.getPos(img.Data);
		}catch(ImageErrorException e){
			
			System.err.println("aaa");
		}
*/
	
	
	public void actualize(OwnImage img) throws ImageErrorException{
		int []pos = ProcIm.getPos(img.Data);
		double x,y,vx,vy;
		long t = timestamp - img.timestamp;
		if(count == 0){
			posX = pos[0];
			posY = pos[1];
			count++;
		}
		else{
			if(count == 1){
			x = (pos[0] + (posX + t*(vX + t * aX)))/2;
			y = (pos[1] + (posY + t*(vY + t * aY)))/2;
			vX = (x-posX)/t;
			vY = (y-posY)/t;
			posX = x;
			posY = y;
			count++;
			}
			else{
				x = (pos[0] + (posX + t*(vX + t * aX)))/2;
				y = (pos[1] + (posY + t*(vY + t * aY)))/2;
				vx = ((x-posX)/t + vX + aX*t)/2;
				vy = ((y-posY)/t + vY + aY*t)/2;
				aX = (vx - vY)/t;
				aY = (vy - vY)/t;
				vX = vx;
				vY = vy;
				posX = x;
				posY = y;
			}
		}		
		timestamp = img.timestamp;
	}
	
	//! PosX visszateritese
	/*!
	  \return int
	*/
	public double getPosX() {
		return posX;
	}
	//! Posy visszateritese
	/*!
	  \return int
	*/
	public double getPosY() {
		return posY;
	}
	//! sebesseg visszateritese
	/*!
	  \return double
	*/
	public double getVelocity() {
		return Math.sqrt(vX*vX+vY*vY);
	}
	//! gyorsulas visszateritese
	/*!
	  \return double
	*/
	public double getAcceleration() {
		return Math.sqrt(aX*aX+aY*aY);
	}
}
